#ifndef ABILITYLISTMODEL_H
#define ABILITYLISTMODEL_H

#include <QAbstractListModel>
#include <QStringList>

class AbilityListModel : public QAbstractListModel
{
    Q_OBJECT
public:
    explicit AbilityListModel(QObject *parent = 0);

signals:

public slots:

    // ADD
    void addAbility(QString name, QString categ, QString subcateg = QString(), QString userFmt = QString("%1"));

    // REMOVE
    bool removeOne(QString name, QString categ = QString(), QString subcateg = QString());
    bool removeAt(const QModelIndex& idx);

    // GET
    QString getAbility(int idx) const;
    QString getCategory(int idx) const;
    QString getSubCategory(int idx) const;    
    QString getCategory(QString abName) const;
    QString getSubCategory(QString abName) const;

    // FILTERS
    void applyFilter(QString filter);
    void applyFilters(QStringList filters);

    // QAbstractListModel
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    QVariant data(const QModelIndex &index, int role) const;
    bool setData(const QModelIndex &index, const QVariant &value, int role);
    Qt::ItemFlags flags(const QModelIndex &index) const;

    AbilityListModel* clone() const;

private:
    class AbilityItemModel
    {
    public:
        AbilityItemModel(QString name, QString categ, QString subcateg = QString())
            : abName(name), abCateg(categ), abSubcateg(subcateg)
        {
            abUserFormat = "%1";
        }

        QString  abName;
        QString  abCateg;
        QString  abSubcateg;
        QVariant abUserFormat;

        QString fullCategName() const
        {
            if ( abSubcateg.isEmpty() )
                return abCateg;
            return QString("%1: %2").arg(abCateg).arg(abSubcateg);
        }

        QString toString() const
        {
            if ( abName.isEmpty() )
                return fullCategName();
            return abName;
        }
    };

    bool applyFilter(QString filter, AbilityItemModel& item);

    QList<AbilityItemModel> abilities;
    QMap<QString, AbilityItemModel> abilMap;
};

#endif // ABILITYLISTMODEL_H
